/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fontys.time;
import java.util.*;

/**
 *
 * @author Administrator
 */
public class Appointment {
   
    private String subject;
    private IPeriod period;
    private ArrayList<Contact> contacts;
    
    public Appointment(String subject, IPeriod period){
        this.subject = subject;
        this.period = period;
        this.contacts = new ArrayList<Contact>();
    }
    
    /**
     * Gets the subject
     * @return the subject
     */
    public String getSubject() {
        return this.subject;
    }
    
    /**
     * Gets the period
     * @return the period
     */
    public IPeriod getPeriod() {
      return this.period; 
   }
    
    /**
     * Gets the invitees
     * @return the invitees of this contact
     */
    public Iterator<Contact> invitees() {
        return contacts.iterator();
    }
    
    /**
     * Adds a new contact to this appointment
     * @param c The contact to add the appointment to
     * @Throws IllegalArgumentException whenever the contact has an overlapping
     * appointment with this appointment.
     */
    public void addContact(Contact c){
        try
        {
            c.addAppointment(this);
        }
        catch(IllegalArgumentException e)
        {
            throw new IllegalArgumentException(e.getMessage());
        }
        this.contacts.add(c);
    }
    
    public void removeContact(Contact c){
        try{
            c.removeAppointMent(this);
        }
        catch(IllegalArgumentException ex){
            throw new IllegalArgumentException(ex.getMessage());
        }
        this.contacts.remove(c);
    }
}
